package org.example.myleet.p897;

import org.example.myleet.Utils.Assert;
import org.example.myleet.Utils.Parser;
import org.example.myleet.Utils.TreeNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class Main {

    public static void main(String[] args) {
        Solution solution = new Solution();
        Assert.isTrue(Assert.isPass(new Integer[]{1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9}, serialize(solution.increasingBST(Parser.parse(new Integer[]{5,3,6,2,4,null,8,1,null,null,null,7,9})))));
        Assert.isTrue(Assert.isPass(new Integer[]{1,null,5,null,7}, serialize(solution.increasingBST(Parser.parse(new Integer[]{5,1,7})))));
    }

    private static Integer[] serialize(TreeNode node) {
        TreeNode cur = node;
        List<Integer> result = new ArrayList<>();
        while (cur != null) {
            result.add(cur.val);
            if (cur.right != null) {
                result.add(cur.left == null ? null : cur.left.val);
            }
            cur = cur.right;
        }
        return result.toArray(new Integer[0]);
    }
}
